package com.yasha.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.yasha.sharingnews.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListChuyenMucAdapter extends BaseAdapter {
	
	private static LayoutInflater inflater = null;
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;

	public ListChuyenMucAdapter(Activity a,ArrayList<HashMap<String, String>> data) {
		activity = a;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	public class ViewHolder {
		public TextView txt_name;
		public ImageView img_cm;

	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		ViewHolder holder;
		if (convertView == null) {
			vi = inflater.inflate(R.layout.list_item_chuyen_muc, null);
			holder = new ViewHolder();
			holder.txt_name = (TextView) vi.findViewById(R.id.list_item_chuyen_muc_txt_name);
			holder.img_cm = (ImageView) vi.findViewById(R.id.list_item_chuyen_muc_img);
			vi.setTag(holder);
		} else
			holder = (ViewHolder) vi.getTag();
		HashMap<String, String> value= data.get(position);
		holder.txt_name.setText( value.get("name").toString().trim());
		holder.img_cm.setBackgroundResource( Integer.parseInt(value.get("img").toString()));
		
		return vi;
	}

}
